﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.Profile;

namespace Continental.Admin
{
    public partial class ManagerAccountTuDiemAdd : System.Web.UI.Page
    {
        public String message = "";
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Page.Validate("CAPNHAP");
            if (Page.IsValid)
            {
                String userName = this.txtEmail.Text.Trim();
                String password = this.txtPassword.Text;
                String email = this.txtEmail.Text.Trim();
                MembershipUser theUser1 = Membership.GetUser(userName);
                if (theUser1 != null)
                {
                    message += "Email đã tồn tại" + "<br />";
                    return;
                }
                if (password.Length < 6 || password.Length > 15)
                {
                    message += "Mật khẩu phải có từ 6->15 kí tự" + "<br />";
                    return;
                }

                MembershipUser theUser = Membership.CreateUser(userName, password, email);
                Roles.AddUserToRole(userName, "TuDiemUser");
                ProfileBase theProfile = ProfileBase.Create(theUser.UserName);
                //if (this.fulAvartar.HasFile)
                //{
                //    String fileName = fulAvartar.PostedFile.FileName;
                //    String fileType = Path.GetExtension(fileName);
                //    String newFileName = DateTime.Now.Ticks.ToString() + fileType;
                //    fulAvartar.PostedFile.SaveAs(Server.MapPath("~/") + "ImageData//Avartar//" + newFileName);
                //    theProfile.SetPropertyValue("Avartar", newFileName);
                //}
                theProfile.SetPropertyValue("FullName", this.txtFullName.Text.Trim());
                theProfile.SetPropertyValue("Mobile", this.txtMobile.Text.Trim());
                theProfile.SetPropertyValue("Avartar", "no_avarta.jpg");
                theProfile.Save();
                message = "Đăng kí thành công";
                Response.Redirect("ManagerTuDiemAddNew.aspx?Email=" + theUser.Email);
            }
            else
            {
                message += "Bạn hãy kiểm tra lại thông tin";
            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("ManagerTuDiem.aspx");
        }
    }
}
